<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
	<meta http-equiv="X-UA-Compatable" content="IE=edge,Chrome=1.0">
	<meta name="format-detection" content="telephone=no">
	<meta name="format-detection" content="email=no">   
	<title>购买记录</title>
	
	<link rel="stylesheet" href="{$_C.hy_path}css/main5.css">
	<link  rel="stylesheet" href="{$_C.hy_path}css/normalize.css">
</head>
<body >
	<div class="banner">
		<img src="{$_C.hy_path}/images/picture/banner.jpg" alt="">
		<div class="user_image">
			<img src="{$info.headimgurl}" alt="">
			<p>{$info.nickname}</p>
		</div>
	</div>
	<div class="stuff_list record">
		<p class="title"><span></span>购物记录</p>
		{foreach from=$list item=record}
		
		
		{if $record.pay_status == "SUCCESS" && $record.can > 0 }
		
		<!-- 可领取 -->
		<a href="javascript:get_card_after_saved({$record.id})" class="stuff row">
		{elseif $record.pay_status == "SUCCESS"}
		
		<!-- 已领取 -->
		<a href="javascript:void(0)" class="stuff row">	
		{else}
		
		<!-- 马上支付 -->
		<a onClick="flgSubmitInfo2({$record.id})"  class="stuff row">	
		{/if}
						
		
		
		
			<div class="col radio visible_none">
				<p><span></span></p>
			</div>
			<div class="col">
				<img src="{$_C.hy_path}/images/picture/little_king.png" alt="">
			</div>
			<div class="col">
				<small>{$record.created}</small>
				<div class="row">
					<div class="col">
						<p>小王子门票</p>
						<p class="orange">￥{$record.total_fee}</p>
					</div>
					<div class="col">
						{if $record.pay_status == "SUCCESS" && $record.can > 0 }
						<h3>
						可领取
						</h3>
						{elseif $record.pay_status == "SUCCESS"}
						<h3 class="active">
						已领取
						</h3>	
						{else}
						<h3>
						马上支付
						</h3>
						{/if}
						
					</div>
				</div>
			</div>
		</a>
		{/foreach}
	</div>
	<!-- 弹框 -->
<div class="page-alert"></div>
<div class="alertcon hide page-moveFromTop">
	<div style="display: inline-block;width: 25px;height: 25px;float: right;margin-top: 5px;margin-right: 5px;"></div>
	<input type="text" id="name" placeholder="姓名">
	<input type="text" id="phone" placeholder="手机号码">
	<span   class="btn btn-tijiao">提交联系方</span>
</div>

<div class="modal success_xiadan hide">
		<div class="modal_content">
			<img src="{$_C.hy_path}images/prince/success.png" alt="">
			<img src="{$_C.hy_path}images/prince/sure.png" alt="">
		</div>
	</div>
<div class="alert-body"></div>
<div class="alertcon2 alert-massage page-moveFromTop hide">
	<p id="msg">消息</p>
	<div class="btn-con">
		<input type="button" class="btn">
	</div>
</div>
<script src="{$_C.hy_path}/js/less.min.js"></script>
<script src="{$_C.hy_path}/js/zepto.min.js"></script>
<script src="{$_C.hy_path}/js/main.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	
<script>
		    var is_saved = {$is_saved};
		 var is_send = false;
		  wx.config({
		    debug: false, 
		   appId: '{$jsdk.appId}',
				timestamp: {$jsdk.timestamp},
				nonceStr: '{$jsdk.nonceStr}',
				signature: '{$jsdk.signature}',
		    jsApiList: [
		      // 所有要调用的 API 都要加到这个列表中
			  'onMenuShareTimeline',
	      	  'onMenuShareAppMessage',
		      'addCard',
			  'chooseWXPay'
		     
		    ]
		  });
		
		  
		  wx.ready(function () {
			
			 wx.onMenuShareTimeline({
			    title: '【G4慈善专场】小王子体验馆门票',
			     link:'http://g4.shfyuan.com/xy/index.php?g=mobile&m=wxpay&a=main',
			     imgUrl: 'http://g4.shfyuan.com/xy/Mobile/Webroot/gf/images/picture/little_king.png',
			      trigger: function (res) {
			       
			      },
			      success: function (res) {
			    	 // document.getElementById('mcover').style.display='';
					//	showMsg("分享成功。");
			      },
			      cancel: function (res) {
			       
			      },
			      fail: function (res) {
			        showMsg(JSON.stringify(res));
			      }
		    });
		    
			wx.onMenuShareAppMessage({
			    link:'http://g4.shfyuan.com/xy/index.php?g=mobile&m=wxpay&a=main',
			     title: '【G4慈善专场】小王子体验馆门票',
			    desc: '【G4慈善专场】小王子体验馆门票--每一张正票我们有10元 捐给爱心直达基金',
			  	imgUrl: 'http://g4.shfyuan.com/xy/Mobile/Webroot/gf/images/picture/little_king.png',
			    success: function () { 
			    	//document.getElementById('mcover').style.display='';
			    	//showMsg("分享成功。");
			    },
			    cancel: function () { 
			        // 用户取消分享后执行的回调函数
			    }
		});
			  
		  
	 	 
 	  
		  });
		    function saveInfo(callBack){
				var saveUrl = "index.php?g=mobile&m=wxpay&a=saveUser";
				var name = $("#name").val();
				var phone = $("#phone").val();
				if(name==""){
					showMsg("请填写姓名");
					return false;
				}
				if(phone==""){
					showMsg("请填写电话号码");
					return false;
				}
				var date = {
						name:name,
						phone:phone
				}
				$.post(saveUrl,date,function(res){
					if(res.error==0){
						callBack();
					}else if(res.error==2){
						showMsg("请刷新页面后，重新点击领取");
					}else{
						showMsg(res.content);
					}
				},"json");
			}
		  
		  function get_card_after_saved(id){
		  	if(is_send)return false;
			is_send = true;
		  	if(!is_saved){
				$('.alertcon .btn-tijiao').unbind("click");
				console.info(22222);
				$('.alertcon .btn-tijiao').click(function(e){
					console.info(1111);
					e.preventDefault();
					function successback(){
						is_saved = true;
						showMsg3("保存成功",try_card,id);
						$('.alertcon').addClass('hide');
			         	$('.page-alert').removeClass('alert-wrapper');
						
					}
					saveInfo(successback);
				})
				$('.page-alert').addClass('alert-wrapper');
			    $('.alertcon').removeClass('hide');
			}else{
				try_card(id);
			}
		  }
		  function try_card(id)
		  {
			
			  var url = "index.php?g=mobile&m=picture&a=ajaxCard";
				
			  var data = { id:id };
			  
				$.post(url,data,function(cardlist){
					 wx.addCard({
			              cardList: cardlist,
			              success: function (res) {
			            	
			            	  
			            	  
			            	  get_card(res,id);
			            	  
			              }
			            });
					 
					  is_send = false;
				},"json");
          	  
            	
		  }
		  
		  
		  function get_card(data,id)
		  {
				  
			  var url = "index.php?g=mobile&m=picture&a=getCard&id="+id;
				
				$.post(url,data,function(res){
					//showMsg("领取成功。");
					$(".success_xiadan").removeClass("hide");
					
					//document.getElementById('mcover').style.display='block';
					
				},"text");
          	  
            
		  }
		  
		   function flgSubmitInfo2(id){
		   	console.info(id);
			 	 var url = "index.php?g=mobile&m=wxpay&a=chooseWXPay&wx_pay_id="+id;
				$.get(url,function(res){
						if(res.error=="1"){
							showMsg(res.content);
						}else{
							wx.chooseWXPay({
							    nonceStr: res.result.nonceStr, 
							    package: res.result.package,
							    paySign: res.result.paySign,
							    signType: res.result.signType,
							    timestamp: res.result.timeStamp, 
							    success: function (resu) {
									if(resu.errMsg == "chooseWXPay:ok"){
			                           successPayOrderQuery(res.out_trade_no);
			                        }
			
							    }
							});
						}
				},"json");
			 }
			 
			$('.alertcon2 .btn-con').click(function(){
			    $('.alertcon2').addClass('hide');
			    $('.alert-body').removeClass('alert-wrapper');
			});
			 
			 
		   function showMsg(msg){
				is_send = false;
				$("#msg").html(msg);
				$('.alertcon2').removeClass('hide');
			    $('.alert-body').addClass('alert-wrapper');
			 }
		   function showMsg2(msg,url){
				is_send = false;
				$('.info-top .closebtn').unbind("click");
				$('.info-top .closebtn').click(function(){
					window.location.href = url;
					$('.info-top').addClass('hide');
					$('.alert-body').removeClass('alert-wrapper');
					$('.info-top .closebtn').unbind("click");
					$('.info-top .closebtn').click(function(){
						$('.alertcon2').addClass('hide');
				    	$('.alert-body').removeClass('alert-wrapper');	
					});				
				});
				$("#msg").html(msg);
				$('.alertcon2').removeClass('hide');
			    $('.alert-body').addClass('alert-wrapper');
				
			 }
			  function showMsg3(msg,callback,id){
				is_send = false;
				$('.info-top .closebtn').unbind("click");
				$('.info-top .closebtn').click(function(){
					$('.info-top').addClass('hide');
					$('.alert-body').removeClass('alert-wrapper');
					$('.info-top .closebtn').unbind("click");
					$('.info-top .closebtn').click(function(){
						$('.alertcon2').addClass('hide');
				    	$('.alert-body').removeClass('alert-wrapper');	
					});
					callback(id);		
				});
				$("#msg").html(msg);
				$('.alertcon2').removeClass('hide');
			    $('.alert-body').addClass('alert-wrapper');
			 }
			function successPayOrderQuery(out_trade_no){
			 	 var url = "index.php?g=mobile&m=wxpay&a=orderquery&out_trade_no="+out_trade_no;
				$.get(url,function(res){
					if(res=="SUCCESS"){
						showMsg2("下单成功","index.php?g=mobile&m=picture&a=record");
						
					}else{
						showMsg("下单失败");
					}
				},"text");
			 }
		</script>
		
</body>
</html>